package cn.jlkj2012.csmall.product.teacher.controller;


import cn.jlkj2012.csmall.product.teacher.pojo.dto.AlbumAddNewDTO;
import cn.jlkj2012.csmall.product.teacher.pojo.dto.AlbumUpdateDTO;
import cn.jlkj2012.csmall.product.teacher.pojo.vo.AlbumListItemVO;
import cn.jlkj2012.csmall.product.teacher.pojo.vo.AlbumStandardVO;
import cn.jlkj2012.csmall.product.teacher.service.IAlbumService;
import cn.jlkj2012.csmall.product.teacher.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
@Slf4j
@Api(tags = "04. 相册管理模块")
@RestController
@RequestMapping("/albums")
public class AlbumController {
    @Autowired
    private IAlbumService albumService;

    public AlbumController() {
        log.debug("创建控制器对象：AlbumController");
    }

    // http://localhost:9080/albums/add-new
    @ApiOperation("添加相册")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult addNew(@Valid AlbumAddNewDTO albumAddNewDTO) {
        log.debug("开始处理【添加相册】的请求，参数：{}", albumAddNewDTO);
        albumService.addNew(albumAddNewDTO);
        return JsonResult.ok();
    }

    // http://localhost:9080/albums/9527/delete
    @ApiOperation("删除相册")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id", value = "相册ID", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult delete(@PathVariable Long id) {
        log.debug("开始处理【根据id删除相册】的请求，参数：{}", id);
        albumService.delete(id);
        return JsonResult.ok();
    }

    // http://localhost:9080/albums/9527/update
    @ApiOperation("修改相册基本信息")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParam(name = "id", value = "相册ID", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/update")
    public JsonResult updateInfoById(@PathVariable Long id, AlbumUpdateDTO albumUpdateDTO) {
        log.debug("开始处理【修改相册基本信息】的请求，参数ID：{}，新数据：{}", id, albumUpdateDTO);
        albumService.updateInfoById(id, albumUpdateDTO);
        return JsonResult.ok();
    }

    // http://localhost:9080/albums/9527
    @ApiOperation("根据id查询相册详情")
    @ApiOperationSupport(order = 410)
    @ApiImplicitParam(name = "id", value = "相册ID", required = true, dataType = "long")
    @GetMapping("/{id:[0-9]+}")
    public JsonResult getStandardById(@PathVariable Long id) {
        log.debug("开始处理【根据id查询相册详情】的请求，参数：{}", id);
        AlbumStandardVO album = albumService.getStandardById(id);
        return JsonResult.ok(album);
    }

    // http://localhost:9080/albums
    @ApiOperation("查询相册列表")
    @ApiOperationSupport(order = 420)
    @GetMapping("")
    public JsonResult list() {
        log.debug("开始处理【查询相册列表】的请求，参数：无");
        List<AlbumListItemVO> list = albumService.list();
        return JsonResult.ok(list);
    }

}
